﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Center.aspx.cs" Inherits="WebForms_Center" %>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
    <section class="featured">
        <div class="content-wrapper" dir="rtl">
           مرکز
        </div>
    </section>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
    <script lang="jv" type="text/javascript">
        function SelectItem(sender, e) {
            e.IsValid = (e.Value != '0');
        }
        </script>

    <asp:MultiView ID="MultiView1" runat="server">
        <asp:View ID="ShowView" runat="server">
            <div dir="rtl" style="width: 100%;">
                <asp:ImageButton ID="NewImageButton" runat="server" OnClick="NewImageButton_Click" SkinID="DatabaseAddButton" />
                <asp:ImageButton ID="SearchImageButton" runat="server" OnClick="SearchImageButton_Click"
                    SkinID="SearchButton" />
                <asp:ImageButton ID="ClearImageButton" runat="server" OnClick="ClearImageButton_Click"
                    OnClientClick="return false;" SkinID="ClearButton" />
                <br />
                <asp:Label ID="CenterNameLabel" runat="server" Text="نام مرکز:" SkinID="Caption" CssClass="lable"></asp:Label>
                <asp:TextBox ID="CenterNameTextBox" runat="server" SkinID="TextBox"></asp:TextBox>
                <asp:Label ID="CenterPassLabel" runat="server" Text="رمز شناسایی:" SkinID="Caption" CssClass="lable"></asp:Label>
                <asp:TextBox ID="CenterPassTextBox" runat="server" SkinID="TextBox"></asp:TextBox>
                <asp:Label ID="SizePageLabel" runat="server" Text="سایز صفحه:" SkinID="Caption" CssClass="lable"></asp:Label>
                <asp:DropDownList ID="PageSizeDropDownList" SkinID="SearchDropDownList" runat="server">
                    <asp:ListItem Selected="True" Value="5">[پیش فرض]</asp:ListItem>
                    <asp:ListItem Value="5">5 رکورد</asp:ListItem>
                    <asp:ListItem Value="10">10 رکورد</asp:ListItem>
                    <asp:ListItem Value="15">15 رکورد</asp:ListItem>
                    <asp:ListItem Value="20">20 رکورد</asp:ListItem>
                    <asp:ListItem Value="25">25 رکورد</asp:ListItem>
                    <asp:ListItem Value="1000000">تمام رکورد ها</asp:ListItem>
                </asp:DropDownList>
            </div>
            <br />
         <div style="float: right; width: 90%;vertical-align:top;" dir="rtl" class="gvclass">
                <asp:GridView ID="CenterGridView" runat="server" AllowPaging="True" AllowSorting="True"
                    DataKeyNames="PkCenterID" DataSourceID="CenterEntityDataSource"
                    Width="100%" AutoGenerateColumns="False" OnSelectedIndexChanged="CenterGridView_SelectedIndexChanged">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:ImageButton ID="SelectImageButton" runat="server" CommandName="Select" SkinID="SelectButton" />
                            </ItemTemplate>
                            <ItemStyle Width="25px" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="PkCenterID" HeaderText="PkCenterID" ReadOnly="True" SortExpression="PkCenterID" Visible="False" />
                        <asp:TemplateField HeaderText="منطقه">
                            <ItemTemplate>
                                <asp:DropDownList ID="LocationDropDownList" runat="server" Enabled="False" SkinID="GridDropDownList"
                                    DataSourceID="LocationEntityDataSource" DataTextField="Name" DataValueField="ID"
                                    SelectedValue='<%# Bind("FkLocationID") %>'>
                                </asp:DropDownList>
                            </ItemTemplate>
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="CenterName" HeaderText="نام مرکز" SortExpression="CenterName">
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="CenterPass" HeaderText="رمز شناسایی مرکز" SortExpression="CenterPass">
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="200px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="200px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="Tel" HeaderText="تلفن" SortExpression="Tel">
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="Address" HeaderText="آدرس" SortExpression="Address">
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="200px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="200px" />
                        </asp:BoundField>
                    </Columns>
                </asp:GridView>               
            </div>
        </asp:View>
        <asp:View ID="EditView" runat="server">
            <div dir="rtl" style="width: 25%; float: right">&nbsp;</div>
            <div dir="rtl" style="width: 50%; float: right">
                <asp:FormView ID="CenterFormView" runat="server" DataSourceID="CenterEntityDataSource" DataKeyNames="PkCenterID" DefaultMode="Insert" Width="100%">
                    <EditItemTemplate>
                        <asp:Label ID="FkLocationIDLabel" runat="server" Text="منطقه:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:DropDownList ID="FkLocationIDDropDownList" runat="server" 
                            DataSourceID="LocationEntityDataSource" DataTextField="Name" DataValueField="ID"
                            SelectedValue='<%# Bind("FkLocationID") %>'>
                        </asp:DropDownList>
                        <asp:CustomValidator ID="LocationCustomValidator" runat="server" ClientValidationFunction="SelectItem"
                            ControlToValidate="FkLocationIDDropDownList" Display="Dynamic" ErrorMessage="*" ValidateEmptyText="True"
                            ValidationGroup="Update"></asp:CustomValidator>
                        <br />
                        <asp:Label ID="CenterNameLabel" runat="server" Text="نام مرکز:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="CenterNameTextBox" runat="server" Text='<%# Bind("CenterName") %>' />
                        <asp:RequiredFieldValidator ID="CenterNameRequiredFieldValidator" runat="server" ControlToValidate="CenterNameTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                        <br />
                        <asp:Label ID="CenterPassLabel" runat="server" Text="رمز شناسایی مرکز:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="CenterPassTextBox" runat="server" Text='<%# Bind("CenterPass") %>' />
                        <br />
                        <asp:Label ID="LALabel" runat="server" Text="طول جغرافیایی:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="LATextBox" runat="server" Text='<%# Bind("LA") %>' />
                        <asp:RangeValidator ID="LARangeValidator" runat="server" ControlToValidate="LATextBox" Display="Dynamic" ErrorMessage="مقدار وارد شده باید عدد باشد" Type="Double" ValidationGroup="Update"></asp:RangeValidator>
                        <br />
                        <asp:Label ID="LELabel" runat="server" Text="عرض جغرافیایی:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="LETextBox" runat="server" Text='<%# Bind("LE") %>' />
                         <asp:RangeValidator ID="LERangeValidator" runat="server" ControlToValidate="LETextBox" Display="Dynamic" ErrorMessage="مقدار وارد شده باید عدد باشد" Type="Double" ValidationGroup="Update"></asp:RangeValidator>
                        <br />
                        <asp:Label ID="AreaLabel" runat="server" Text="مساحت:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="AreaTextBox" runat="server" Text='<%# Bind("Area") %>' />
                         <asp:RangeValidator ID="AreaRangeValidator" runat="server" ControlToValidate="AreaTextBox" Display="Dynamic" ErrorMessage="مقدار وارد شده باید عدد باشد" Type="Double" ValidationGroup="Update"></asp:RangeValidator>
                        <br />
                        <asp:Label ID="PersonNoLabel" runat="server" Text="تعداد پرسنل:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="PersonNoTextBox" runat="server" Text='<%# Bind("PersonNo") %>' />
                        <asp:RequiredFieldValidator ID="PersonNoRequiredFieldValidator" runat="server" ControlToValidate="PersonNoTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="PersonNoRangeValidator" runat="server" ControlToValidate="PersonNoTextBox" Display="Dynamic"
                            ErrorMessage="مقدار وارد شده باید عدد باشد" Type="Integer" ValidationGroup="Update" MinimumValue="0" MaximumValue="2147483647"></asp:RangeValidator>
                        <br />
                        <asp:Label ID="TelLabel" runat="server" Text="تلفن:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="TelTextBox" runat="server" Text='<%# Bind("Tel") %>' />
                        <br />
                        <asp:Label ID="FaxLabel" runat="server" Text="فکس:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="FaxTextBox" runat="server" Text='<%# Bind("Fax") %>' />
                        <br />
                        <asp:Label ID="AddressLabel" runat="server" Text="آدرس:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' TextMode="MultiLine" Width="300px" />
                        <asp:RequiredFieldValidator ID="AddressRequiredFieldValidator" runat="server" ControlToValidate="AddressTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                        <br />
                        <div style="float: left; padding: 10px;">
                            <asp:LinkButton ID="DeleteLinkButton" runat="server" CausesValidation="False" CommandName="Delete" CssClass="button"
                                OnClientClick="if (!confirm('آيا از حذف مطمئن هستيد؟')) return false;" Text="حذف" />

                            <asp:LinkButton ID="UpdateLinkButton" runat="server" CommandName="Update"
                                ValidationGroup="Update" OnClientClick="if (!confirm('آيا از اعمال تغییرات مطمئن هستيد؟')) return false;" Text="ویرایش" CssClass="button" />

                            <asp:LinkButton ID="CancelLinkButton" runat="server" CommandName="Cancel" Text="انصراف" CssClass="button" />
                        </div>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:Label ID="FkLocationIDLabel" runat="server" Text="منطقه:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:DropDownList ID="FkLocationIDDropDownList" runat="server" 
                            DataSourceID="LocationEntityDataSource" DataTextField="Name" DataValueField="ID"
                            SelectedValue='<%# Bind("FkLocationID") %>'>
                        </asp:DropDownList>
                        <asp:CustomValidator ID="LocationCustomValidator" runat="server" ClientValidationFunction="SelectItem"
                            ControlToValidate="FkLocationIDDropDownList" Display="Dynamic" ErrorMessage="*" ValidateEmptyText="True"
                            ValidationGroup="Insert"></asp:CustomValidator>
                        <br />
                        <asp:Label ID="CenterNameLabel" runat="server" Text="نام مرکز:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="CenterNameTextBox" runat="server" Text='<%# Bind("CenterName") %>' />
                        <asp:RequiredFieldValidator ID="CenterNameRequiredFieldValidator" runat="server" ControlToValidate="CenterNameTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                        <br />
                        <asp:Label ID="CenterPassLabel" runat="server" Text="رمز شناسایی مرکز:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="CenterPassTextBox" runat="server" Text='<%# Bind("CenterPass") %>' />
                        <br />
                        <asp:Label ID="LALabel" runat="server" Text="طول جغرافیایی:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="LATextBox" runat="server" Text='<%# Bind("LA") %>' />
                         <asp:RangeValidator ID="LARangeValidator" runat="server" ControlToValidate="LATextBox" Display="Dynamic" ErrorMessage="مقدار وارد شده باید عدد باشد" Type="Double" 
                             ValidationGroup="Insert" ></asp:RangeValidator>
                        <br />
                        <asp:Label ID="LELabel" runat="server" Text="عرض جغرافیایی:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="LETextBox" runat="server" Text='<%# Bind("LE") %>' />
                         <asp:RangeValidator ID="LERangeValidator" runat="server" ControlToValidate="LETextBox" Display="Dynamic" ErrorMessage="مقدار وارد شده باید عدد باشد" Type="Double"
                              ValidationGroup="Insert"  ></asp:RangeValidator>
                        <br />
                        <asp:Label ID="AreaLabel" runat="server" Text="مساحت:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="AreaTextBox" runat="server" Text='<%# Bind("Area") %>' />
                         <asp:RangeValidator ID="AreaRangeValidator" runat="server" ControlToValidate="AreaTextBox" Display="Dynamic" ErrorMessage="مقدار وارد شده باید عدد باشد" Type="Double" ValidationGroup="Insert"></asp:RangeValidator>
                        <br />
                        <asp:Label ID="PersonNoLabel" runat="server" Text="تعداد پرسنل:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="PersonNoTextBox" runat="server" Text='<%# Bind("PersonNo") %>' />
                        <asp:RequiredFieldValidator ID="PersonNoRequiredFieldValidator" runat="server" ControlToValidate="PersonNoTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="PersonNoRangeValidator" runat="server" ControlToValidate="PersonNoTextBox" Display="Dynamic"
                            ErrorMessage="مقدار وارد شده باید عدد باشد" Type="Integer" ValidationGroup="Insert" MinimumValue="0" MaximumValue="2147483647"></asp:RangeValidator>
                        <br />
                        <asp:Label ID="TelLabel" runat="server" Text="تلفن:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="TelTextBox" runat="server" Text='<%# Bind("Tel") %>' />
                        <br />
                        <asp:Label ID="FaxLabel" runat="server" Text="فکس:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="FaxTextBox" runat="server" Text='<%# Bind("Fax") %>' />
                        <br />
                        <asp:Label ID="AddressLabel" runat="server" Text="آدرس:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' TextMode="MultiLine" Width="300px" />
                        <asp:RequiredFieldValidator ID="AddressRequiredFieldValidator" runat="server" ControlToValidate="AddressTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                        <br />
                        <div style="float: left; padding: 10px;">
                            <asp:LinkButton ID="InsertLinkButton" runat="server" CommandName="Insert" Text="ایجاد" CssClass="button"
                                ValidationGroup="Insert" />
                            <asp:LinkButton ID="CancelLinkButton" runat="server" CommandName="Cancel" Text="انصراف" CssClass="button" />
                        </div>
                    </InsertItemTemplate>
                </asp:FormView>
            </div>
        </asp:View>
    </asp:MultiView>

    <asp:EntityDataSource ID="LocationEntityDataSource" runat="server" ConnectionString="name=ICTBillingEntities" DefaultContainerName="ICTBillingEntities"
        EnableFlattening="False"
        CommandText="(SELECT  it.[PkLocationID] As ID, it.[LocationName] As Name FROM ICTBillingEntities.tbLocations AS it) UNION (SELECT x.[ConstantValue] as ID,x.[ConstantName] As Name from ICTBillingEntities.tbConstants as x where x.PkConstantID=2)">
    </asp:EntityDataSource>

    <asp:EntityDataSource ID="CenterEntityDataSource" runat="server" ConnectionString="name=ICTBillingEntities" DefaultContainerName="ICTBillingEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="tbCenters" OnDeleted="CenterEntityDataSource_Command"
        OnInserted="CenterEntityDataSource_Command" OnUpdated="CenterEntityDataSource_Command"
        Where="(@CenterName is null || it.CenterName LIKE '%' + @CenterName + '%') AND (@CenterPass is null || it.CenterPass LIKE '%' + @CenterPass + '%')">
        <WhereParameters>
            <asp:ControlParameter ControlID="CenterNameTextBox" Name="CenterName" Type="String" />
            <asp:ControlParameter ControlID="CenterPassTextBox" Name="CenterPass" Type="String" />
        </WhereParameters>
    </asp:EntityDataSource>
</asp:Content>

